// pages/setParking/setParking.js
let request = require('../../utils/request')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    managerId: 0,
    managerInfo: {},
    nameVal: '',
    phoneVal: '',
    parkId: 0,
    totalParkSpaceVal: '',
    reserveParkSpaceVal: '',
    chargingParkSpaceVal: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let id = options.id ? options.id : 0
    this.setData({
      managerId: id,
      parkId: options.parkId,
      parkingInfo: {
        parkId: options.parkId,
        chargingParkSpace: options.chargingParkSpace,
        reserveParkSpace: options.reserveParkSpace,
        totalParkSpace: options.totalParkSpace
      },
      chargingParkSpaceVal: options.chargingParkSpace,
      reserveParkSpaceVal: options.reserveParkSpace,
      totalParkSpaceVal: options.totalParkSpace,
      managerInfo: {}
    })
  },
  /**
 * 获取泊位总数
 */
  getPhoneVal(e) {
    let val = e.detail.value
    if (val.length >= 11) {
      val = val.slice(0, 11)
    }
    this.setData({
      phoneVal: val
    })
  },
  /**
   * 获取可约泊位
   */
  getTotalParkSpaceVal(e) {
    let val = e.detail.value
    this.setData({
      totalParkSpaceVal: val
    })
  },
  /**
   * 获取充电桩
   */
  getReserveParkSpaceVal(e) {
    let val = e.detail.value
    this.setData({
      reserveParkSpaceVal: val
    })
  },
  /**
   * 修改停车场信息
   */
  setParkingInfo() {
    let parmas = this.data.parkingInfo
    parmas['totalParkSpace'] = this.data.totalParkSpaceVal
    parmas['reserveParkSpace'] = this.data.reserveParkSpaceVal
    parmas['chargingParkSpace'] = this.data.chargingParkSpaceVal
    request.http('/park/park-info/audit-parkinfo-space', 'POST', parmas, 0)
      .then(res => {
        let data = res.data
        if (data.code == 200) {
          wx.showToast({
            title: '修改成功',
          })
        }
      })
  }
})